package com.ftwj.controller;

import com.ftwj.entity.SysMenu;
import com.ftwj.service.SysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/menus")
public class SysMenuController {

    @Autowired
    private SysMenuService sysMenuService;

    /**
     * 添加父菜单
     * @param menu 父菜单对象
     * @return 操作结果
     */
    @PostMapping("/addParent")
    public boolean addParentMenu(@RequestBody SysMenu menu) {

        return sysMenuService.addParentMenu(menu);
    }

    /**
     * 添加子菜单
     * @param menu 子菜单对象
     * @return 操作结果
     */
    @PostMapping("/addChild/{id}")
    public boolean addChildren(@PathVariable("id") String id, @RequestBody SysMenu menu) {

        return sysMenuService.addChildren(id,menu);
    }

    /**
     * 获取所有父菜单
     * @return 父菜单列表
     */
    @GetMapping("/getParents")
    public List<SysMenu> getParents() {
        return sysMenuService.getParentMenus();
    }
    @GetMapping("/findByMenuName")
    public List<SysMenu> findMenuByMenuName(@RequestParam("menuName") String name) {
        return sysMenuService.findMenuByMenuName(name);
    }

}
